package model

import "yi-shou-backstage/util"

// 频道
type Channel struct {
    ID int `gorm:"primaryKey;comment:频道id" json:"id" validate:"omitempty"`
    Name string `gorm:"type:varchar(32);not null;comment:频道名称" json:"name,omitempty" validate:"omitempty" label:"频道名称"`
}

func CreateChannel(obj Channel) *Channel {
    err := db.Create(&obj).Error
    if err != nil {
        util.LogEntry.Errorf("Create channel fialed, error = %s \n", err)
        return nil
    }
    return &obj
}

func ListChannels() (int64, []Channel) {
    var channels []Channel
    var total int64
    err := db.Find(&channels).Count(&total).Error
    if err != nil {
        util.LogEntry.Errorf("List channels fialed, error = %s \n", err)
        return total, channels
    }
    return total, channels
}
